package src.leetcode.greedy.medium_0452;

import java.util.Arrays;
import java.util.Comparator;

public class findMinArrowShots {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.findMinArrowShots(new int[][]{{1,2},{2,3},{3,4},{4,5}}));
    }
}


class Solution {
    public int findMinArrowShots(int[][] points) {
        if (points.length == 0) {
            return 0;
        }
        Arrays.sort(points, ((o1, o2) -> o1[0]<o2[0]?-1:1));
        int count = 0;
        for(int i = 0; i < points.length;){
            int arrow = points[i][1];
            count++;
            while (i < points.length && points[i][0] <= arrow) {
                arrow = Math.min(arrow, points[i][1]);
                i++;
            }
        }
        return count;
    }
}